package com.mybank.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mybank.mapper.TransactionRecordMapper;
import com.mybank.pojo.TransactionRecord;
import com.mybank.service.TransactionRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Service
public class TransactionRecordServiceImpl extends ServiceImpl<TransactionRecordMapper, TransactionRecord> implements TransactionRecordService {
    @Autowired
    private TransactionRecordMapper transactionRecordMapper;
    /**
     * 按卡号分页查询交易记录
     * @param params 入参
     * @return
     */
    @Override
    public Page<TransactionRecord> getPage(HashMap<String, String> params) {
        LambdaQueryWrapper<TransactionRecord> lqw = new LambdaQueryWrapper<>();
        lqw.eq(TransactionRecord::getCardno,params.get("loginCardNo"))
                .ge(TransactionRecord::getTransactionDate,params.get("startDate"))
                .le(TransactionRecord::getTransactionDate,params.get("endDate"));
        Page page = new Page(){{
           setCurrent(Long.parseLong(params.get("pageCurrent")));
           setSize(Long.parseLong(params.get("pageSize")));
        }};
        return transactionRecordMapper.selectPage(page,lqw);
    }
}
